package com.zr.util;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtil {
	private static final SessionFactory sf = bulidSessionFactory();
	   
	   private  HibernateUtil(){};
	   private  static SessionFactory bulidSessionFactory(){
		    //读取配置文件，创建sessionFactory工厂
			 Configuration  config  = (Configuration) new Configuration().configure();
           //注册服务 
			 ServiceRegistry  sr =  new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
			
			 return  config.buildSessionFactory(sr);
	 
	   }
	   public static SessionFactory getSf() {
		return sf;
	}
}
